<template>
  <view class="profile-header">
    <view class="header-content">
      <view class="user-info">
        <view class="avatar">
          <image src="/static/img/user-avatar.png" mode="aspectFill" />
          <text v-if="!avatarLoaded" class="avatar-fallback">JD</text>
        </view>
        <view class="user-text">
          <text class="greeting">早上好，张同学</text>
          <text class="journey">继续你的AI学习之旅 ✨</text>
        </view>
      </view>
      <view class="actions">
        <view class="action-button" @tap="toggleSearch">
          <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <circle cx="11" cy="11" r="8"></circle>
            <path d="m21 21-4.3-4.3"></path>
          </svg>
        </view>
        <view class="action-button">
          <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"></path>
            <path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"></path>
          </svg>
          <view class="notification-dot"></view>
        </view>
      </view>
    </view>

    <view v-if="showSearch" class="search-container">
      <view class="search-input-wrapper">
        <svg class="search-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
          fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
          <circle cx="11" cy="11" r="8"></circle>
          <path d="m21 21-4.3-4.3"></path>
        </svg>
        <input class="search-input" placeholder="搜索课程、技能或讲师..." auto-focus />
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const showSearch = ref(false);
const avatarLoaded = ref(false);

const toggleSearch = () => {
  showSearch.value = !showSearch.value;
};

onMounted(() => {
  // 模拟图片加载
  setTimeout(() => {
    avatarLoaded.value = true;
  }, 500);
});
</script>

<style scoped>
.profile-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #3b82f6;
  overflow: hidden;
}

.avatar image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #dbeafe;
  color: #1d4ed8;
  font-weight: 500;
}

.user-text {
  display: flex;
  flex-direction: column;
}

.greeting {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.journey {
  font-size: 12px;
  color: #3b82f6;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.action-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #f1f5f9;
  color: #64748b;
}

.notification-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #f43f5e;
}

.search-container {
  padding: 0 16px 12px 16px;
  animation: slideDown 0.3s ease-in-out;
}

.search-input-wrapper {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background-color: #f8fafc;
  font-size: 14px;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>